package com.gxitsky.utils;

import com.clearofchina.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 * 患者中心工具类
 */
@Slf4j
public class PatientCenterUtil {

    private static final String CERT_NO_REG_EXP = "^[1-9][0-9]{5}(18|19|20)[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}([0-9]|[Xx])";

    private static final Pattern CERT_NO_PATTERN = Pattern.compile(CERT_NO_REG_EXP);

    /**
     * 加密
     */
    public static String enc(String text) {

        if (StringUtils.isBlank(text)) {
            return null;
        }

        try {
            return DesUtil.enc(text, DesUtil.DEFAULT_KEY);
        } catch (Exception e) {
            throw new BusinessException(e);
        }
    }

    /**
     * 解密
     */
    public static String dec(String text) {

        if (StringUtils.isBlank(text)) {
            return null;
        }

        try {
            return DesUtil.dec(text, DesUtil.DEFAULT_KEY);
        } catch (Exception e) {
            throw new BusinessException(e);
        }
    }
}
